if(USE_GOOGLE_TEST)
  find_package(GTest CONFIG)
  if(NOT GTest_FOUND)
    message(STATUS "GTest: pre-installed googletest NOT found")
    message(STATUS "GTest: install step")
    include(FetchContent)
    FetchContent_Declare(
      googletest
      GIT_REPOSITORY https://gitee.com/mirrors/googletest.git
      # ~~~
      # GIT_TAG d25e625364a2078c940da2cb1fcf098aa184fd9f # 202304170423
      # GIT_TAG dea0484e4d3b6a2c50055c24c5617cd662a50c5f # 202304281020
      # ~~~
      GIT_TAG cb455a71fb23303e37ce8ee5b1cde6a2c18f66a5 # 202305221514
    )

    # Prevent overriding the parent project's compiler/linker settings
    set(gtest_force_shared_crt
        ON
        CACHE BOOL "" FORCE)
    FetchContent_MakeAvailable(googletest)
    message(STATUS "GTest: install step - Success")
  else()
    message(STATUS "GTest: found")
    set_target_properties(GTest::gtest_main PROPERTIES IMPORTED_GLOBAL TRUE)
    add_library(gtest_main ALIAS GTest::gtest_main)
    get_target_property(GTest_INCLUDE_DIR GTest::gtest_main
                        INTERFACE_INCLUDE_DIRECTORIES)
  endif()
endif()

set(SRC_PATH "${CMAKE_SOURCE_DIR}/src")
set(MPI_SRC_PATH "${SRC_PATH}/mpi")
set(HYPERCUBE_SRC_PATH "${SRC_PATH}/hypercube")
set(LINEAR_SRC_PATH "${SRC_PATH}/linear")
set(POWEROF2_SRC_PATH "${SRC_PATH}/powerof2")

file(GLOB GENERAL_SRCS ${SRC_PATH}/*.cpp)
file(GLOB MPI_SRCS ${MPI_SRC_PATH}/*.cpp)
file(GLOB HYPERCUBE_SRCS ${HYPERCUBE_SRC_PATH}/*.cpp)
file(GLOB LINEAR_SRCS ${LINEAR_SRC_PATH}/*.cpp)
file(GLOB POWEROF2_SRCS ${POWEROF2_SRC_PATH}/*.cpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_subdirectory(block)
add_subdirectory(mpi)
add_subdirectory(Cifar10)
add_subdirectory(CNN)
add_subdirectory(hypercube)
add_subdirectory(linear)
add_subdirectory(powerof2)

if(USE_GOOGLE_TEST)
  create_target(test_igemm "test_cblas_igemm.cpp" "mkl;gtest")
endif()
